﻿using System.Linq.Expressions;
using System.Reflection;

namespace BrightSword.Feber.Core
{
    public abstract class UnaryOperationBuilderBase<TProto, TInstance> : OperationBuilderBase<TProto>
    {
// ReSharper disable StaticFieldInGenericType
        private static readonly ParameterExpression _parameterExpression = Expression.Parameter(typeof (TInstance),
                                                                                                "_instance");

// ReSharper restore StaticFieldInGenericType

        protected virtual ParameterExpression InstanceParameterExpression
        {
            get
            {
                return _parameterExpression;
            }
        }

        protected override Expression BuildPropertyExpression(PropertyInfo propertyInfo)
        {
            //try
            //{
            return PropertyExpression(propertyInfo,
                                      InstanceParameterExpression);
            //}
            //catch
            //{
            //    return Expression.Default(typeof (void));
            //}
        }

        protected abstract Expression PropertyExpression(PropertyInfo property,
                                                         ParameterExpression instanceParameterExpression);
    }
}